package com.caocao.service.impl;

import com.caocao.domain.AccountConst;
import com.caocao.domain.mapper.TUserMapper;
import com.caocao.domain.model.TUser;
import com.caocao.domain.model.TUserExample;
import com.caocao.service.UserService;
import com.caocao.utils.VerifyUtil;
import org.apache.log4j.spi.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述:用户业务逻辑实现类
 *
 * @Author:操文健
 * @Create Time:2017-09-10 2:29
 */
@Service
public class UserServiceImpl implements UserService {

    private static final Logger logger = org.slf4j.LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired
    private TUserMapper tUserMapper;
    /**
     * 实现用户的登陆验证方法
     * @param userCode
     * @param passWd
     * @return
     */
    @Override
    public TUser getUserForNameAndPass(String userCode, String passWd) {
        logger.info("开始验证用户的登陆信息...");

        // 界面数据非空判断
        if (VerifyUtil.isEmptyString(userCode) || VerifyUtil.isEmptyString(passWd)) {
            logger.info("用户名或者密码为空,返回为null");
            return null;
        }
        TUserExample tUserExample  = new TUserExample();
        tUserExample.createCriteria().andUsercodeEqualTo(userCode)
                .andPasswordEqualTo(passWd)
                .andIsvalidEqualTo(AccountConst.FLAG_TEUE);
        List<TUser> tUserList = tUserMapper.selectByExample(tUserExample);
        // 对用户数据库查询的数据进行非空判断
        if (VerifyUtil.isEmpty(tUserList)) {
            logger.info("数据库查询不到对应的用户信息...  返回为空...");
            return  null;
        }
        return tUserList.get(0);
    }
}
